//#include <QtTest/QtTest>
//#include "testechoservice.h"
//#include "testsumservice.h"
//#include "testlogservice.h"
//#include "integrationtest.h"
//
//int main(int argc, char* argv[])
//{
//    QCoreApplication app(argc, argv);
//
//    TestEchoService testEchoService;
//    QTest::qExec(&testEchoService, argc, argv);
//
//    TestSumService testSumService;
//    QTest::qExec(&testSumService, argc, argv);
//
//    TestLogService testLogService;
//    QTest::qExec(&testLogService, argc, argv);
//
//    IntegrationTest integrationTest;
//    QTest::qExec(&integrationTest, argc, argv);
//
//    return 0;
//}



#include <QtCore/QCoreApplication>
#include <QThreadPool>
#include <QSettings>
#include "server.h"
#include "servermonothread.h"
#include "servermultithread.h"
#include "echoservice.h"
#include "sumservice.h"
#include "logservice.h"


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QSettings settings("settings.ini",QSettings::IniFormat);
    bool multithreadActive = settings.value("server/multithreadActive", false).toBool();
    int threadCount = settings.value("server/threadCount", -1).toInt();
    int port = settings.value("server/port", 1601).toInt();
    int waitForAnswer = settings.value("server/waitForAnswer", -1).toInt();
    QString serviceSettings = settings.value("server/service", "sum").toString();

    if(threadCount == -1)
    {
        threadCount = QThread::idealThreadCount();
    }

    Service *service;

    if(serviceSettings == "sum")
    {
        service = new SumService;
    }
    else if(serviceSettings == "log")
    {
        service = new LogService;
    }
    else if(serviceSettings == "echo")
    {
        service = new EchoService;
    }
    else
    {
        service = new SumService;
    }

    QThreadPool::globalInstance()->setMaxThreadCount(100);

    Server *server;
    if(multithreadActive)
        server = new ServerMultithread(service, waitForAnswer);
    else
        server = new ServerMonothread(service, waitForAnswer);

    QThreadPool::globalInstance()->setMaxThreadCount(threadCount);

    server->listen(QHostAddress::Any,port);
    return a.exec();
}
